/**
 * @fileOverview The "sizesaver" plugin.
 */
(function() {

   VED.plugins.add( 'sizesaver', {
      init: function( editor ) {
         var config = editor.config, timer;

         var width  = VED.tools.cookieGet( editor.name + '_width' );
         width && ( config.width = width );

         var height = VED.tools.cookieGet( editor.name + '_height' );
         height && ( config.height = height );

         editor.on('resize', function( evt ){
            timer && clearTimeout( timer );
            timer = VED.tools.setTimeout(function(){
               var container = evt.editor.ui.space( 'contents' );
               VED.tools.cookieSet( evt.editor.name + '_width',  container.getSize('width'), {duration: 30});
               VED.tools.cookieSet( evt.editor.name + '_height', container.getSize('height') - 1, {duration: 30});
               timer = null;
            }, 100 );
         });
      }
   });

})();


